<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<script type="text/javascript">
	$(document).ready(function() {
		//생일이 숫자인지 실시간체크하기
		$("#birthday").keyup(function() {
			var birthNum = $("#birthday").val();
			if (isNaN(birthNum)) {
				$("#checkNumSpace").html("생일은 숫자로만 입력해주세요");
			}else if(birthNum.length!=8){
				$("#checkNumSpace").html("생일은 8자리로 입력해주세요");	
			} else {
				$("#checkNumSpace").html("");
			}
		});//생일이 적었을 때 

		//회원가입 폼 빈칸체크
		$("#updateForm").submit(function() {
			if ($("form [name=id]").val() == "") {
				alert("id를 입력해 주세요");
				return false;
			} else if ($("form [name=password]").val() == "") {
				alert("비밀번호를 입력해 주세요");
				return false;
			} else if ($("form [name=name]").val() == "") {
				alert("이름을 입력해 주세요");
				return false;
			} else if ($("form [name=address]").val() == "") {
				alert("주소를 입력해 주세요");
				return false;
			} else if ($("form [name=birthday]").val() == "") {
				alert("생일을 입력해 주세요");
				return false;
			} else if ($("form [name=gender]").is(':checked') == false) {
				alert("성별을 선택해 주세요");
				return false;
			} else if ($("form [name=cellphone]").val() == "") {
				alert("비밀번호를 입력해 주세요");
				return false;
			} else if ($("form [name=email]").val() == "") {
				alert("e-mail 주소를 입력해 주세요");
				return false;
			} else if ($("#checkNumSpace").text() != "") {
				alert("생일은 숫자로만 입력해주세요");
				return false;
			} else if ($("#checkIdDuplSpace").text() != "") {
				alert("아이디가 중복되었습니다");
				return false;
			}

		});//수정 버튼 클릭시
		$("#pictureDeleteBtn").click(function(){
			$.ajax({
				type:"post",
				url:"${initParam.root}member.do",
				dataType:"json",
				data:"command=deletePicture",
				success:function(data){
					//alert(data.delPicResult);
					$("#picSpace").html("사진올리기: <input type='file' name='uploadFile'>");
					
				}//success
			});//ajax
		});//사진 삭제 버튼 눌렀을 때
	});
</script>

	<c:choose>
		<c:when test="${sessionScope.userInfo==null}">
			<script type="text/javascript">
				alert("로그인 후에 이용가능한 서비스입니다");
				location.href = "${initParam.root}member.do?command=home";
			</script>
		</c:when>
		<c:otherwise>
			<h2>회원정보수정</h2>
			<br>
			<form id="updateForm" action="${initParam.root }member.do"
				method="post" enctype="multipart/form-data">
				
				<div id="picSpace">
				<c:choose>
					<c:when test="${sessionScope.userInfo.saveFileName==null }">
						사진올리기: <input type="file" name="uploadFile" id="uploadFileBtn">
						<br>
					</c:when>
					<c:otherwise>
						<img src="${initParam.root }upload/${sessionScope.userInfo.saveFileName}" width="150" height="170"><br>
						<input type="button" value="사진삭제" id="pictureDeleteBtn">
					</c:otherwise>
				</c:choose>
				</div>
				
				<input type="hidden" name="command" value="update"> <br>
				id: <input type="text" name="id" value="${sessionScope.userInfo.id }"readonly="readonly"><br> password: <input
					type="password" name="password"><br> 이름: <input
					type="text" name="name" value="${requestScope.info.name }"><br>
				주소: <input type="text" name="address"
					value="${requestScope.info.address }"><br> 생일( 8자리로
				입력해주세요. 예시 - 19900908): <input type="text" name="birthday"
					id="birthday" value="${requestScope.info.birthday }"> <span
					id="checkNumSpace"></span><br>

				<c:if test="${requestScope.info.gender == 'male'}">
			성별:<input type="radio" name="gender" value="male" checked="checked">남
	 		<input type="radio" name="gender" value="female">여<br>
				</c:if>
				<c:if test="${requestScope.info.gender == 'female'}">
			성별:<input type="radio" name="gender" value="male">남
	 		<input type="radio" name="gender" value="female" checked="checked">여<br>
				</c:if>

				전화번호: <input type="text" name="cellphone"
					value="${requestScope.info.cellphone }"><br> e-mail: <input
					type="text" name="email" value="${requestScope.info.email }"><br>
				<input type="submit" value="회원정보수정">
			</form>
		</c:otherwise>
	</c:choose>
